/*     */ package com.newcrm.util;
/*     */ 
/*     */ import java.io.PrintStream;
/*     */ 
/*     */ public class GB2Alpha
/*     */ {
/*   6 */   private char[] chartable = { '啊', 33453, '擦', '搭', 34558, '发', '噶', '哈', '哈', '击', '喀', '垃', '妈', '拿', '哦', '啪', '期', '然', '撒', '塌', '塌', '塌', '挖', '昔', '压', '匝', '座' }; private char[] alphatable = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z' }; private int[] table = new int[27];
/*     */ 
/*   6 */   public GB2Alpha() { for (int i = 0; i < 27; i++) this.table[i] = gbValue(this.chartable[i]);
/*     */   }
/*     */ 
/*     */   public char char2Alpha(char ch)
/*     */   {
/*  30 */     if ((ch >= 'a') && (ch <= 'z')) {
/*  31 */       return (char)(ch - 'a' + 65);
/*     */     }
/*  33 */     if ((ch >= 'A') && (ch <= 'Z')) {
/*  34 */       return ch;
/*     */     }
/*  36 */     int gb = gbValue(ch);
/*  37 */     if (gb < this.table[0]) {
/*  38 */       return '0';
/*     */     }
                int i = 0;
/*  40 */     for (i = 0; i < 26; i++) {
/*  41 */       if (match(i, gb)) {
/*     */         break;
/*     */       }
/*     */     }
/*  45 */     if (i >= 26) {
/*  46 */       return '0';
/*     */     }
/*     */ 
/*  49 */     return this.alphatable[i];
/*     */   }
/*     */ 
/*     */   public String string2Alpha(String source)
/*     */   {
/*  55 */     StringBuffer result = new StringBuffer();
/*  56 */     int StrLength = source.length();
/*     */     try
/*     */     {
/*  59 */       for (int i = 0; i < StrLength; i++)
/*  60 */         result.append(char2Alpha(source.charAt(i)));
/*     */     }
/*     */     catch (Exception e) {
/*  63 */       result = new StringBuffer();
/*     */     }
/*  65 */     return result.toString();
/*     */   }
/*     */ 
/*     */   private boolean match(int i, int gb)
/*     */   {
/*  70 */     if (gb < this.table[i]) {
/*  71 */       return false;
/*     */     }
/*  73 */     int j = i + 1;
/*     */ 
/*  76 */     while ((j < 26) && (this.table[j] == this.table[i])) {
/*  77 */       j++;
/*     */     }
/*  79 */     if (j == 26) {
/*  80 */       return gb <= this.table[j];
/*     */     }
/*  82 */     return gb < this.table[j];
/*     */   }
/*     */ 
/*     */   private int gbValue(char ch)
/*     */   {
/*  88 */     String str = "";
/*  89 */     str = str + ch;
/*     */     try {
/*  91 */       byte[] bytes = str.getBytes("GB2312");
/*  92 */       if (bytes.length < 2) {
/*  93 */         return 0;
/*     */       }
/*  95 */       return (bytes[0] << 8 & 0xFF00) + (bytes[1] & 0xFF); } catch (Exception e) {
/*     */     }
/*  97 */     return 0;
/*     */   }
/*     */ 
/*     */   public static void main(String[] args)
/*     */   {
/* 102 */     GB2Alpha obj1 = new GB2Alpha();
/* 103 */     System.out.println(obj1.string2Alpha("陈胜"));
/* 104 */     System.out.println(obj1.string2Alpha("zc"));
/*     */   }
/*     */ }

/* Location:           C:\E\referenceProject\CRM参考\qikebao\WEB-INF\lib\qikebao.jar
 * Qualified Name:     com.newcrm.util.GB2Alpha
 * JD-Core Version:    0.6.1
 */